using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public class RepeatHelper : NodeHelper
    {
        public GameObject item;
        public int number;
        private readonly List<GameObject> list = new();

        protected override BindDataType bindDataType => BindDataType.Int;

        protected override void BindData(int i)
        {
            if (number == i) return;
            number = i;
            for (var j = 0; j < list.Count; j++)
                if (j >= i)
                    list[i].SetActive(false);
            for (var j = 0; j < i; j++)
            {
                if (j >= list.Count) list.Add(Instantiate(item, gameObject.transform));

                list[j].SetActive(true);
            }
        }
    }
}